﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;

public partial class Manager_DetailCandidate : System.Web.UI.Page
{
    string id;
    protected void Page_Init(object sender, EventArgs e)
    {
        if (Request.QueryString["CanID"] != "" && Request.QueryString["CanID"] != null)
        {
            id = Request.QueryString["CanID"];
            DataTable tblData = new DataTable();
            tblData = RegisterCandidate.GetDetailCandidate(id);
            txtUserName.Text = tblData.Rows[0]["Username"].ToString();
            txtAddress.Text = tblData.Rows[0]["Address"].ToString();
            txtCertifience.Text = tblData.Rows[0]["Certificate"].ToString();
            txtEmail.Text = tblData.Rows[0]["Email"].ToString();
            txtExperience.Text = tblData.Rows[0]["Experience"].ToString();
            txtFullname.Text = tblData.Rows[0]["FullName"].ToString();
            txtMobile.Text = tblData.Rows[0]["Mobile"].ToString();
        }
        else
        {
            Response.Redirect("CandidateManager.aspx");
        }

    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["CanID"] == "")
            Response.Redirect("CandidateManager.aspx");
                

    }
    protected void btnUpdate_Click(object sender, EventArgs e)
    {
        int canID = Int16.Parse(id);

        Candidate can = new Candidate();

        can.ID = canID;
        can.Email = txtEmail.Text;
        can.Certificate = txtCertifience.Text;
        can.Experience = txtExperience.Text;
        can.Fullname = txtFullname.Text;
        can.Address = txtAddress.Text;
        can.Mobile = txtMobile.Text;

        bool check;
        check = RegisterCandidate.UpdateCandidate(canID, txtEmail.Text, txtCertifience.Text, txtExperience.Text, txtFullname.Text, txtMobile.Text, txtAddress.Text);

        if (check)
            Session.Add("Message", "Update successfully CandidateID : " + canID);
        else
            Session.Add("Message", "<font color='red'>Error : Update unsuccess CandidateID : " + canID + "</font>");

        Response.Redirect("CandidateManager.aspx");


    }

    protected void btnChanger_Click(object sender, EventArgs e)
    {
        Response.Redirect("ChangerPassCandidate.aspx?canID="+id);
    }
}